home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / fbug68k.arc / LO.C < prev    next >
C/C++ Source or Header  |  1989-08-17  |  5KB  |  181 lines

  1. #include"userdef.h"
  2.  
  3. /* ************************************************* */
  4. /* 
  5. lo [<offset>] [<text>]
  6. Load S-Record -> This command loads s records, adding <offset> to the address
  7. in the s-record. The text is sent to the HOST computer port to start
  8. the s-records flowing.
  9. The "lo " part of the command line is stripped away. Then a test is made
  10. to see if the <offset> is present or not. Then any <text> is obtained and 
  11. sent to the HOST port.
  12. The a skip to prime the pump is made. Then the type of s record is found.
  13. If it is data, then the data is obtined, keeping track of the checksum, the
  14. data is put into memory and the checksum is compared at the end of the line.
  15. If it is the end of the s-records a message is printed and the command quits.
  16. Otherwise, the s-record is skipped.
  17. If the checksum doesn't match, then an error message is printed and the
  18. control is returned to the main loop.
  19. */
  20. /* ************************************************* */
  21.  
  22. locmd(argc,argv)
  23. int argc;    /* number of arguments on the command line */
  24. char *argv;    /* the command line */
  25. {
  26.  
  27. extern int error;    /* global error flag from getnum */
  28. int checksum;    /* checksum */
  29. int offset_to_addr;    /* the offset to add to the address */
  30. int type;    /* the type of s-record */
  31. int length;    /* the length of the number of characters on the 
  32.                 s-record line */
  33. int address;    /* the address to insert data into */
  34. int data;    /* the data to insert */
  35. int i;        /* a temporary loop counter */
  36.  
  37.     striparg(argv);
  38.     if (argc > 1 && argv[0] != ';')
  39.     {
  40.         offset_to_addr = getnum(argv,ERR03,DEFAULTSCALE);
  41.         if (error)
  42.             return(0);
  43.     }
  44.     else
  45.         offset_to_addr = 0;
  46. print("offset==%x\n",offset_to_addr);
  47.     if ( argc > 1 && argv[0] == ';')
  48.     {
  49.         for(i=1;(argv[i] != ENDSTR && i<=MAXLINE);i++)
  50.             putch(HOST,argv[i]);
  51.         putch(HOST,CR);
  52.         putch(HOST,LF);
  53.     }
  54.     skiptos();
  55.     while(TRUE)
  56.     {
  57.         type = getch(HOST,TRUE);
  58.         putch(TERMINAL,type);
  59.         type = type - '0';
  60.         address = 0;
  61.         length = getspair(0,FALSE,TRUE);
  62.         checksum = length;/* length, address and code/data fields will
  63.                     be added    */
  64.         switch (type)
  65.         {
  66.             case 0:
  67.                 for(i=0;i<length+1;i++)
  68.                     data=getspair(0,FALSE,TRUE);
  69.                 skiptos();
  70.                 break;
  71.             case 1:
  72.             case 2:
  73.             case 3:
  74.                 for(i=0;i<=type;i++)
  75.                 {
  76.                     data = getspair(0,FALSE,TRUE);
  77.                     checksum = (data + checksum) & MASK8;
  78.                     address = (address << 8) | data;
  79.                     length--;
  80.                 }
  81.                 print("\n");
  82.                 address = address + offset_to_addr;
  83.                 for(i=1;i<length;i++)
  84.                     checksum = ((getspair(address++,TRUE,FALSE) + checksum) & MASK8);
  85.                 data = (getspair(0,FALSE,FALSE) & MASK8);
  86.                 if (((data - ~checksum) & MASK8) != 0)
  87.                 {
  88.                     print(ERR08);
  89.                     print("%c%x, %c%x expected.\n",HEXDEL,data,HEXDEL,(~checksum & MASK8));
  90.                     print("length=%d\n",length);
  91.                     print("address=%x\n",address);
  92.                     return(0);
  93.                 }
  94.                 skiptos();
  95.                 break;
  96.             case 7:
  97.             case 8:
  98.             case 9:
  99.                 type = 10 - type;
  100.                 while (type-- >= 0)
  101.                 {
  102.                     data = getspair(0,FALSE,TRUE);
  103.                     checksum = (data + checksum) & MASK8;
  104.                     address = (address << 8) | data;
  105.                     length--;
  106.                 }
  107.                 address = address + offset_to_addr;
  108.                 while (length-- > 1)
  109.                     checksum = ((getspair(0,FALSE,FALSE) + checksum) & MASK8);
  110.                 if (((getspair(0,FALSE,FALSE) - ~checksum) & MASK8) != 0)
  111.                 {
  112.                     print(ERR08);
  113.                     print("%c%x\n",HEXDEL,(~checksum & MASK8));
  114.                     return(0);
  115.                 }
  116.                 print("\n S-record load successful\n");
  117.                 return(0);
  118.                 break;
  119.             default:
  120.                 print("%d S-record encountered\n",type);
  121.                 skiptos();
  122.                 break;
  123.         }
  124.     }
  125. }
  126.  
  127. /* ***************************************************** */
  128. skiptos()
  129. {
  130. char S;
  131.  
  132.     while (TRUE)
  133.         {
  134.         S = getch(HOST);
  135.         if (S == 's' || S == 'S')
  136.             {
  137.             print("S");
  138.             break;
  139.             }
  140.         }
  141. }
  142. /* ***************************************************** */
  143. /* 
  144. getspair gets 2 characters in the s-record format. If insert is
  145. true it will insert them into memory at addr.
  146. */
  147. /* ***************************************************** */
  148.  
  149. getspair(addr,insert,print)
  150. int addr;    /* address to insert information */
  151. int insert;    /* flag to insert information or not */
  152. int print;    /* flag to print information or not */
  153. {
  154. register char ch1;    /* first charachter */
  155. register char ch2;    /* second charchter */
  156. int returnvalue;
  157.     
  158.     ch1 = getch(HOST,TRUE);
  159.     if(print)
  160.         putch(TERMINAL,ch1);
  161.     ch2 = getch(HOST,TRUE);
  162.     if(print)
  163.         putch(TERMINAL,ch2);
  164.     if (ch1 >= '0' && ch1 <= '9')
  165.         ch1 = ch1 - '0';
  166.     else if (ch1 >= 'A' && ch1 <= 'F')
  167.         ch1 = ch1 - 'A' + 10;
  168.     else if (ch1 >= 'a' && ch1 <= 'f')
  169.         ch1 = ch1 - 'a' + 10;
  170.     if (ch2 >= '0' && ch2 <= '9')
  171.         ch2 = ch2 - '0';
  172.     else if (ch2 >= 'A' && ch2 <= 'F')
  173.         ch2 = ch2 - 'A' + 10;
  174.     else if (ch2 >= 'a' && ch2 <= 'f')
  175.         ch2 = ch2 - 'a' + 10;
  176.     returnvalue = ((ch1 << 4) | ch2) & MASK8;
  177.     if (insert == TRUE)
  178.         put8(addr,returnvalue);
  179.     return(returnvalue);
  180. }
  181.